<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>后台管理系统</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- favicon
		============================================ -->
    <link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico">
    <!-- Google Fonts
		============================================ -->
    <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,700,900" rel="stylesheet">
    <!-- Bootstrap CSS
		============================================ -->
    <link rel="stylesheet" href="css/bootstrap.min.css">

    <!-- Lobibox CSS
        ============================================ -->
    <link rel="stylesheet" href="css/notifications/Lobibox.min.css">

    <!-- Bootstrap CSS
		============================================ -->
    <link rel="stylesheet" href="css/font-awesome.min.css">


    <!-- DatetimePicker CSS
        ============================================ -->
    <link rel="stylesheet" href="css/datetimepicker/bootstrap-datetimepicker.min.css">

    <!-- owl.carousel CSS
		============================================ -->
    <link rel="stylesheet" href="css/owl.carousel.css">
    <link rel="stylesheet" href="css/owl.theme.css">
    <link rel="stylesheet" href="css/owl.transitions.css">
    <!-- animate CSS
		============================================ -->
    <link rel="stylesheet" href="css/animate.css">
    <!-- normalize CSS
		============================================ -->
    <link rel="stylesheet" href="css/normalize.css">
    <!-- meanmenu icon CSS
		============================================ -->
    <link rel="stylesheet" href="css/meanmenu.min.css">
    <!-- main CSS
		============================================ -->
    <link rel="stylesheet" href="css/main.css">
    <!-- educate icon CSS
		============================================ -->
    <link rel="stylesheet" href="css/educate-custon-icon.css">
    <!-- morrisjs CSS
		============================================ -->
    <link rel="stylesheet" href="css/morrisjs/morris.css">
    <!-- mCustomScrollbar CSS
		============================================ -->
    <link rel="stylesheet" href="css/scrollbar/jquery.mCustomScrollbar.min.css">
    <!-- metisMenu CSS
		============================================ -->
    <link rel="stylesheet" href="css/metisMenu/metisMenu.min.css">
    <link rel="stylesheet" href="css/metisMenu/metisMenu-vertical.css">
    <!-- calendar CSS
		============================================ -->
    <link rel="stylesheet" href="css/calendar/fullcalendar.min.css">
    <link rel="stylesheet" href="css/calendar/fullcalendar.print.min.css">

    <!-- form CSS
		============================================ -->
    <link rel="stylesheet" href="css/form/all-type-forms.css">

    <!-- style CSS
		============================================ -->
    <link rel="stylesheet" href="css/style.css">
    <!-- responsive CSS
		============================================ -->
    <link rel="stylesheet" href="css/responsive.css">
    <!-- modernizr JS
		============================================ -->
    <script src="js/vendor/modernizr-2.8.3.min.js"></script>

    <style>
        .pagination {
            margin-top: 0;
            margin-bottom: 0;
        }
    </style>
</head>

<body>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>


<![endif]-->
<!-- Start Left menu area -->
<div class="left-sidebar-pro">
    <nav id="sidebar" class="">
        <div class="sidebar-header">
            <a href="index.html"><img class="main-logo" src="img/logo/logo.png" alt="" /></a>
            <strong><a href="index.html"><img src="img/logo/logosn.png" alt="" /></a></strong>
        </div>
        <div class="left-custom-menu-adp-wrap comment-scrollbar">
            <nav class="sidebar-nav left-sidebar-menu-pro">
                <ul class="metismenu" id="menu1">
                    <li>
                        <a title="Landing Page" href="report.html" aria-expanded="false"><span class="fa fa-user-circle-o" aria-hidden="true"></span> <span class="mini-click-non">商城数据</span></a>
                    </li>
                    <li class="active">
                        <a class="has-arrow" href="index.html">
                            <span class="fa fa-id-card"></span>
                            <span class="mini-click-non">用户信息</span>
                        </a>
                        <ul class="submenu-angle" aria-expanded="true">
                            <li><a href="index.html"><span class="mini-sub-pro">用户列表</span></a></li>
                            <li><a href="goodsManager.html"><span class="mini-sub-pro">商品列表</span></a></li>
                            <li><a href="order.html"><span class="mini-sub-pro">订单管理</span></a></li>
                            <li><a href="classify.html"><span class="mini-sub-pro">类目管理</span></a></li>
                            <li><a href="sc.html"><span class="mini-sub-pro">客户服务</span></a></li>
                            <li><a href="notification.html"><span class="mini-sub-pro">通知管理</span></a></li>
                        </ul>
                    </li>
                    <li>
                        <a title="Landing Page" href="adminUser.html" aria-expanded="false"><span class="fa fa-user-circle-o" aria-hidden="true"></span> <span class="mini-click-non">系统用户</span></a>
                    </li>
                </ul>
            </nav>
        </div>
    </nav>
</div>
<!-- End Left menu area -->
<!-- Start Welcome area -->
<div class="all-content-wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="logo-pro">
                    <a href="index.html"><img class="main-logo" src="img/logo/logo.png" alt="" /></a>
                </div>
            </div>
        </div>
    </div>
    <div class="header-advance-area">
        <div class="header-top-area">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                        <div class="header-top-wraper">
                            <div class="row">
                                <div class="col-lg-1 col-md-0 col-sm-1 col-xs-12">
                                    <div class="menu-switcher-pro">
                                        <button type="button" id="sidebarCollapse" class="btn bar-button-pro header-drl-controller-btn btn-info navbar-btn">
                                            <i class="fa fa-bars"></i>
                                        </button>
                                    </div>
                                </div>

                                <div class="col-lg-5 col-md-5 col-sm-12 col-xs-12 col-lg-offset-6 col-md-offse-7 col-sm-offse-6 col-xs-offse-12">
                                    <div class="header-right-info">
                                        <ul class="nav navbar-nav mai-top-nav header-right-menu">
                                            <li class="nav-item dropdown">
                                            </li>
                                            <li class="nav-item">
                                                <div class="dropdown" id="notifyMenu">
                                                    <button type="button" class="btn btn-danger dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown">
                                                        <i class="fa fa-bell" aria-hidden="true"></i>
                                                        <span class="badge" id="unreadNotify">0</span>
                                                        <span class="caret"></span>
                                                    </button>
                                                    <ul class="dropdown-menu"  aria-labelledby="dropdownMenu1" v-if="notifyData.length>0">
                                                        <!--消息列表-->
                                                        <li  v-for="notify in notifyData"  >
                                                            <a href="javascript:void(0)" v-on:click="fn($event)" :value="notify.path" :nid="notify.nid">
                                                                <div class="notification-content">
                                                                    <span class="bg-info" >{{notify.updateTime}}</span>
                                                                    <h5 style="margin-top: 10px">{{notify.title}}</h5>
                                                                    <p>点击查看详细信息</p>
                                                                </div>
                                                            </a>
                                                        </li>
                                                    </ul>
                                                    <ul class="dropdown-menu"  id="" aria-labelledby="dropdownMenu1" v-else>
                                                        <li>
                                                            <span style="font-size: 10px;color: darkgrey">暂无新的通知</span>
                                                        </li>
                                                        <li>
                                                            <a href="notification.html">查看所有通知</a>
                                                        </li>
                                                    </ul>
                                                </div>
                                            </li>
                                            <li class="nav-item">
                                                <a href="#" data-toggle="dropdown" role="button" aria-expanded="false"
                                                   class="nav-link dropdown-toggle">
                                                    <img id="headImgs" src="img/product/pro4.jpg" alt="#"style="width: 30px;height: 30px;border-radius: 100%"/>
                                                    <span class="admin-name" id="headName">欢迎你，xxx</span>
                                                    <i class="fa fa-angle-down edu-icon edu-down-arrow"></i>
                                                </a>
                                                <ul role="menu"
                                                    class="dropdown-header-top author-log dropdown-menu animated zoomIn">

                                                    <li><a onclick="logOut()"><span
                                                            class="edu-icon edu-locked author-log-ic"
                                                            style="cursor:pointer"></span>登出</a>
                                                    </li>
                                                </ul>
                                            </li>

                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="container-fluid" style="padding: 20px 15px 0 15px;">
            <table id="adminUserDatatable" class="table table-bordered table-striped"></table>

            <div id="adminUserTableToolbar" style="margin: 10px 0px;">
                <button class="btn btn-success" onclick="showAddUserModal()">添加</button>
                <button onclick="downloadExcel()" class="btn btn-primary">导出</button>
                <button  onclick="clickFileInput()"  class="btn btn-danger">导入</button>
                <input type="file" id="fileid" onchange="uploadExcel(this)" style="display:none;" name="excel" value="" />
                <a href="http://localhost:8080/posterior_system_war_exploded/endUser/excelmodel">下载模板</a>
               </div>

            <div class="modal" id="addAdnChangeUserModal" data-backdrop="static">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button onclick="destoryAddAndChangeUserModal()" class="close">
                                <span>&times;</span>
                            </button>
                            <h3 class="modal-title" id="title"></h3>
                        </div>
                        <div class="modal-body">
                            <form id="form_verdict">
                                <input type="hidden" id="imageServerPath">
                                <div class="form-group">
                                    <label for="userName">账号</label>
                                    <input class="form-control" autocomplete="off" subUser="true" id="userName" name="inputUserName">
                                </div>
                                <div class="form-group">
                                    <label for="password">密码</label>
                                    <input  class="form-control" autocomplete="off" subPassword="true" id="password" name="inputPassword">
                                </div>
                                <div class="form-group">
                                    <label for="opState">启用</label>
                                    <select class="form-control"  id="opState">
                                        <option value="1" selected>是</option>
                                        <option value="0" >否</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="opAdminUserName">管理员</label>
                                    <select class="form-control" id="opAdminUserName">
                                        <option value="1" >是</option>
                                        <option value="0" selected>否</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>展示图</label>
                                    <div style="margin-bottom: 6px;">
                                        <img src="../images/default.png" width="158px" id="preDisplayImage" height="180px">
                                    </div>
                                    <div class="file-upload-inner file-upload-inner-right ts-forms">
                                        <div class="input append-small-btn">
                                            <div class="file-button">
                                                选择头像
                                                <input id="displayImage" autocomplete="off" onchange="uploadImage(this)" type="file" name="uploadFile">
                                            </div>
                                            <input type="text" autocomplete="off" id="append-small-btn" placeholder="no file selected">
                                        </div>
                                    </div>
                                </div>

                            </form>
                        </div>
                        <div class="modal-footer">
                            <button onclick="destoryAddAndChangeUserModal()" class="btn btn-danger">取消</button>
                            <button  id="commitBtn" class="btn btn-success" optionFunction="" onclick="addAndChangeUser()" value="">确认</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

<!-- jquery
============================================ -->
<script src="js/vendor/jquery-1.12.4.min.js"></script>

<!-- bootstrap JS
============================================ -->
<script src="js/bootstrap.min.js"></script>
<!-- wow JS  动画效果js
============================================ -->
<script src="js/wow.min.js"></script>
<!-- price-slider JS
============================================ -->
<script src="js/jquery-price-slider.js"></script>
<!-- meanmenu JS
============================================ -->
<script src="js/jquery.meanmenu.js"></script>
<!-- owl.carousel JS
============================================ -->
<script src="js/owl.carousel.min.js"></script>
<!-- sticky JS
============================================ -->
<script src="js/jquery.sticky.js"></script>
<!-- scrollUp JS
============================================ -->
<script src="js/jquery.scrollUp.min.js"></script>
<!-- counterup JS
============================================ -->
<script src="js/counterup/jquery.counterup.min.js"></script>
<script src="js/counterup/waypoints.min.js"></script>
<script src="js/counterup/counterup-active.js"></script>
<!-- mCustomScrollbar JS
============================================ -->
<script src="js/scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
<script src="js/scrollbar/mCustomScrollbar-active.js"></script>
<!-- metisMenu JS
============================================ -->
<script src="js/metisMenu/metisMenu.min.js"></script>
<script src="js/metisMenu/metisMenu-active.js"></script>


<script src="js/sparkline/jquery.sparkline.min.js"></script>
<script src="js/sparkline/jquery.charts-sparkline.js"></script>
<script src="js/sparkline/sparkline-active.js"></script>
<!-- calendar JS
============================================ -->
<script src="js/calendar/moment.min.js"></script>

<script src="js/calendar/fullcalendar.min.js"></script>
<script src="js/calendar/fullcalendar-active.js"></script>
<!-- plugins JS
============================================ -->
<script src="js/plugins.js"></script>
<!-- main JS
============================================ -->
<script src="js/main.js"></script>

<!-- tawk chat JS  聊天系统js
<script src="js/tawk-chat.js"></script>
============================================ -->

<script src="js/data-table/bootstrap-table.js"></script>
<script src="js/data-table/bootstrap-table-zh-CN.js"></script>

<script src="js/notifications/Lobibox.js"></script>

<script src="js/datepicker/bootstrap-datetimepicker.min.js"></script>
<script src="js/datepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="js/jquery.validate.min.js" type="application/javascript"></script>
<script src="localization/messages_zh.min.js"></script>
<script src="js/my/meValidate.js"></script>
<script src="js/vue.js"></script>
<script src="customjs/eventSourcesNotify.js"></script>
<link rel="stylesheet" href="customcss/ul_style.css">
</body>

<script>
    var httpHead = "http://localhost/"
    var baseUrl="http://localhost:8080/posterior_system_war_exploded/"
    var baseHttpUrl="http://localhost:8080/posterior_system_war_exploded/endUser"; //user业务处理地址
    var uploadFileUrl ="http://localhost:8080/posterior_system_war_exploded/file/upload";//上传文件地址
    /**
     * 1. 获取浏览器地址栏，然后截取路径。
     * 2. 根据路径使用jquery的选择器让其背景颜色变一下。
     */
    var url = window.location.href;   //获取浏览器地址栏 http://localhost:8081/my_cart_war_exploded/admin/index.html

    var index = url.lastIndexOf("/");  //获取最后一个 / 所在的索引的位置

    var path = '/admin' + url.substring(index);  // /admin/index.html

    $('a[href$="' + path + '"]').css('background-color', '#f7f8fb');





    // 显示错误提示信息
    function showErrorBox(msgText,codeState) {
        var colors='';
        if (codeState>0){
            colors = 'success'
        }else {
            colors = 'warning';
        }
        Lobibox.notify(colors, {
            size: 'mini',
            delay: 2500,
            delayIndicator: false,
            position: 'center top',//定位
            title: false, //不给title
            msg: msgText,
            sound: false  // 不要音频
        })
    }

    /**
     * {
     *           "total": 23,
     *           "rows": [{type: '', }, {}, {}]
     *       }
     */
    $('#adminUserDatatable').bootstrapTable({
        url: baseHttpUrl,
        method: 'GET',
        // data:{method:'showList'},
        columns: [
            // field是返回rows中每个对象的属性名
            {title: '账号', field: 'endName', align: 'center'},
            {title: '密码', field: 'endPassword', align: 'center'},
            {title: '状态', field: 'state', align: 'center', formatter: formatState},
            {title: '超级用户', field: 'adminuser', align: 'center',formatter: formatAdminUser},
            {title: '操作',align:'center',formatter:addProcessBtn}
        ],
        /**
         * 决定了在哪边分页：client server, 两种不同的配置决定了服务器端返回的数据格式。
         *  client分页, 服务器端返回的数据  [{}, {}, {}]
         *  server端分页，服务器端返回的数据：{rows:[{}, {}], total: 23}
         */
        sidePagination: 'server',
        pagination: true, //表示使用分页
        toolbar: '#adminUserTableToolbar'  //设置工具条
    })



    // 格式化用户的状态
    function formatState(value) {
        $("#userId").val()

        if(value== 1) {
            return '<span class="label label-success ">启用</span>'
        }
        return '<span class="label label-warning ">禁用</span>'
    }

    // 格式化用户是否为管理员的状态
    function formatAdminUser(value) {
        if(value == 1) {
            return '<span class="label label-success">是</span>';

        }
        return '<span class="label label-warning">否</span>';
    }
    var userList=[];
    // 添加操作按钮
    function addProcessBtn(value, row) {
        if (row.state ==null){
            row.state=0;
        }
        if(row.adminuser == null){
            row.adminuser=0;
        }

        var endUserId = row.id;
        var btn ='<img id="headUrl" src="'+httpHead+row.headImg+'" style="height: 40px;width: 40px" alt="头像" hidden="hidden" />';
        if (row.state==1){
            btn =btn+ '<button onclick="changeUserState(' + endUserId + ',0)" class="btn btn-danger btn-xs">禁用账户</button>&nbsp; &nbsp;';
        }else {
            btn =btn + '<button onclick="changeUserState(' + endUserId + ',1)" class="btn btn-success btn-xs">启用账户</button>&nbsp; &nbsp;';
        }

        if (row.adminuser==1){
            btn =btn+ '<button onclick="changeAdminUser(' + endUserId + ',0)" class="btn btn-danger btn-xs">禁用管理员</button>&nbsp; &nbsp;';
        }else{
            btn =btn + '<button onclick="changeAdminUser(' + endUserId + ',1)" class="btn btn-success btn-xs">启用管理员</button>&nbsp; &nbsp;';
        }
        btn =btn+ '<button onclick="changeUserModal(' +endUserId+')" class="btn btn-info btn-xs">修改</button>';
        userList.push(row);
        return btn;
    }
    // 改变用户状态
    function changeUserState(userId,userState) {
        $.ajax({
            url: baseHttpUrl,
            data: {id: userId,state:userState},
            dataType: 'json',
            type: 'put',
            success: function(datas) {
                // 表示删除成功，更新表格
                if(datas.code > 0) {
                    $('#adminUserDatatable').bootstrapTable('refresh'); //刷新页面数据
                }else { // 修改失败，给用户一个提示
                    showErrorBox('修改失败, 请联系管理员.')
                }
            }
        })
    }


    // 改变用户权限
    function changeAdminUser(userId,adminUser) {

        $.ajax({
            url: baseHttpUrl,
            data: {id: userId,adminuser:adminUser},
            dataType: 'json',
            type: 'put',
            success: function(datas) {
                // 表示删除成功，更新表格
                if(datas.code > 0) {
                    $('#adminUserDatatable').bootstrapTable('refresh');
                }else { // 修改失败，给用户一个提示
                    showErrorBox('修改失败, 请联系管理员.')
                }
            }
        })
    }
    /**
     * 展示添加的模态框
     *   1. 首先将所有种类查出来，渲染在模态框中的种类下拉列表中
     *   2. 显示模态框
     */
    function showAddUserModal() {
        var optionFunction = $("#commitBtn").attr("optionFunction","add");
        $("#title").text("添加用户");
        var items = $('#items');
        items.empty(); //清空种类的下拉列表
        $('#addAdnChangeUserModal').modal('show');
    }

    /**
     * 展示修改的模态框
     *   1. 首先将所有种类查出来，渲染在模态框中的种类下拉列表中
     *   2.回填数据
     *   3. 显示模态框
     */
    function changeUserModal(userId) {
        var optionFunction = $("#commitBtn").attr("optionFunction","change");
        $("#title").text("修改用户");
        var items = $('#items');

        resetModal();
        console.log(userList);
        userList.forEach(item=>{
            if(userId==item.id){
                //导入属性值
                $('#commitBtn').val(userId)
                $('#userName').val(item.endName);
                $('#password').val(item.endPassword);
                var stateStr="";
                var adminUserSt="";
                $("select option").remove();
                if (item.state == 1){
                     stateStr='<option value="1" selected>是</option><option value="0" >否</option>'
                }else if (item.state == 0 ){
                     stateStr='<option value="1" >是</option><option value="0" selected>否</option>'
                }

                if (item.adminuser==1){
                    adminUserSt=  '<option value="1" selected>是</option><option value="0" >否</option>'
                }else if (item.adminuser==0){
                    adminUserSt=  '<option value="1" >是</option><option value="0" selected>否</option>'

                }
                $("#opState").append(stateStr);
                $("#opAdminUserName").append(adminUserSt);
                var headUrl = "http://localhost/"+item.headimg;
                $("#preDisplayImage").attr("src",headUrl);
              ;
                $("#append-small-btn").val(item.headImg)
            }
        })
        $('#addAdnChangeUserModal').modal('show');
    }




    // 隐藏模态框
    function destoryAddAndChangeUserModal() {
        resetModal();
        $("#commitBtn").attr("optionFunction","");
        $('#addAdnChangeUserModal').modal('hide');
    }

    // /**
    //  * 上传展示图：
    //  *    1.在选择图片旁边的那个输入框中显示文件的名字；
    //  *    2.上传图片。
    //  *    3.回显图片。
    //  */
    function uploadImage(fileTag){

       var displayImage = fileTag.files[0];
       console.log(fileTag);
       console.log(fileTag);
        // console.log(displayImage.name)  //文件的名字，在很多网站中要去判断文件的格式是否正确，要通过后缀来判断
        // console.log(displayImage.size); // 文件的大小，单位是字节，如果要判断多少 M, size / (1024 * 1024) 结果单位就位M
        var name = displayImage.name;

        $('#append-small-btn').val(name);

        var formData = new FormData();
        formData.append('uploadFile', displayImage);
        // formData.append('itemAlias', itemAlias);
        // formData.append('method', 'uploadDisplayImage')

        $.ajax({
            url: uploadFileUrl,
            type: 'post',
            dataType: 'json',
            data: formData,
            /**
             * 内容类型。默认值：application/x-www-form-urlencoded;
             * false表示不设置，将FormData原封不动的直接提价服务器端
             */
            contentType: false,
            /**
             * processData 处理数据， 例如get请求，会将data中的数据，name=张三&password=125,
             * 对于FormData包含文件，此处要为false, 禁止转换
             */
            processData: false,
            success: function(_data) {
                $("#displayImage").val('');
                console.log(_data)
                // {"filePath":"mobile/147617383170300EfssbV3XDA8PFrTsSj.jpg","imageUrl":"http://localhost/mobile/147617383170300EfssbV3XDA8PFrTsSj.jpg"}
                $('#preDisplayImage').prop('src',httpHead+_data.headimg);  //回显图片
                $('#imageServerPath').val(_data.headImgUrl);
            }
        })
    }
    // 关闭模态框的时候，重置所有的信息
    function resetModal() {
        $("#userName").val('');
        $("#password").val('');
        $('#imageServerPath').val('');
        $('#append-small-btn').val('');
        $('#preDisplayImage').attr('src','/cc');
        $("select option").remove();
        var stateStr='<option value="1" selected>是</option><option value="0" >否</option>'
        $("#opState").append(stateStr);
        var adminUserStr=  '<option value="1" >是</option><option value="0" selected>否</option>'
        $("#opAdminUserName").append(adminUserStr);

    }

    //添加修改用户

    function addAndChangeUser(){
        var optionFunction = $("#commitBtn").attr("optionFunction");
        console.log("---optionFunction---");
        console.log(optionFunction);
        var id = $("#commitBtn").val();
        var userName =  $("#userName").val();
        var password =  $("#password").val();
        var state =$("#opState option:selected").val();
        var adminUserName =$("#opAdminUserName option:selected").val();
        var subUser =$('#userName').attr("subUser");
        var subPassword = $('#password').attr("subPassword");
        var headImg = $('#imageServerPath').val();
       // console.log("subUser:"+subUser+"subPassword:"+subPassword);
       if (userName==''){
           showErrorBox("用户名不能为空");
           return;
       }
        if (password==''){
            showErrorBox("密码不能为空");
            return;
        }
        if (subUser!="true") {
            showErrorBox("用户名错误，无法提交");
            return;
        }
        if (subPassword != "true") {
            showErrorBox("密码错误，无法提交");
            return;
        }
        if (optionFunction == "add") {
            $.ajax({
                url: baseHttpUrl,
                type: 'post',
                dataType: 'json',
                data: {
                    endName: userName,
                    endPassword: password,
                    state: state,
                    adminuser:adminUserName,
                    headimg:headImg,
                },
                success: function (datas) {
                    console.log("succcess")
                    if (datas.code > 0) {
                        destoryAddAndChangeUserModal();  //关闭添加模态框
                        $('#adminUserDatatable').bootstrapTable('refresh');

                        showErrorBox(datas.msg, 1);

                    } else {
                        showErrorBox(datas.msg, 0);
                    }
                }

            })
        } else if (optionFunction == "change") {
            $.ajax({
                url: baseHttpUrl,
                type: 'Put',
                dataType: 'json',
                data: {
                    id: id,
                    endName: userName,
                    endPassword: password,
                    state: state,
                    adminuser:adminUserName,
                    headimg:headImg,
                },
                success: function (datas) {
                    if (datas.code > 0) {
                        destoryAddAndChangeUserModal();  //关闭添加模态框
                        $('#adminUserDatatable').bootstrapTable('refresh');
                        showErrorBox(datas.msg, 1);
                    } else {
                        showErrorBox(datas.msg, 0);
                    }
                }

            })
        }
        resetModal();//清空添加用户数据
    }

    //导出excel
    function downloadExcel() {
        location.href =baseHttpUrl+ "/downloadexcel";
    }
    //
    //     $(function(){
    //         var file; // 定义一个全局变量，为一个文本选择器。
    //         file = $(''); // 这样file就是jquery创建的一个文本选择器，但是因为我们并没有把它加载到页面山，所以是不可见的。
    //
    //         // button的单击事件
    //         $('#uploadExcel').click(function(){
    //             // 启动文件选择
    //             file.click();
    //         });
    //
    //         // 选择好文件后，获取选择的内容
    //         file.change(function(e){
    //             var select_file = file[0].files[0];
    //             $("#fileid").val("");
    //             uploadExcel(select_file);
    //
    //         })
    //
    //
    //     })
    //

    function clickFileInput() {
        $("#fileid").click();
    }

    function uploadExcel(fileData) {
        var excelfile = fileData.files[0];
        // var fileName = file.name; //获取文件名
        // var suffix = fileName.substring(fileName.lastIndexOf('.'));
        // if('.xls' != suffix && '.xlsx' != suffix) {
        //     showErrorBox('请上传正确的excel文件.')
        // }
        $("#fileid").val('');
        var formData = new FormData();
        formData.append("excel",excelfile);
        $.ajax({
            url: baseHttpUrl+"/uploadExcel",
            type: 'post',
            dataType: 'json',
            data: formData,
            /**
             * 内容类型。默认值：application/x-www-form-urlencoded;
             * false表示不设置，将FormData原封不动的直接提价服务器端
             */
            contentType: false,
            /**
             * processData 处理数据， 例如get请求，会将data中的数据，name=张三&password=125,
             * 对于FormData包含文件，此处要为false, 禁止转换
             */
            processData: false,
            success: function(_data) {
                if(_data.code>0){
                    showErrorBox(_data.msg,_data.code);
                }else {
                    showErrorBox(_data.msg,_data.code);
                }
            }
        })
    }
    // 显示错误提示信息
    function showErrorBox(msgText,codeState) {
        var colors='';
        if (codeState>0){
            colors = 'success'
        }else {
            colors = 'warning';
        }
        Lobibox.notify(colors, {
            size: 'mini',
            delay: 2500,
            delayIndicator: false,
            position: 'center top',//定位
            title: false, //不给title
            msg: msgText,
            sound: false  // 不要音频
        })
    }

    //用户登出
    function logOut() {



        $.ajax({
            url: baseUrl+"login/out",
            method: 'get',
            dataType: "json",
            async:true,
            success:function (_data) {
                console.log("----datas.code----");
                console.log(_data.code);
                if (_data.code>0){
                    console.log("--成功--");
                    window.location.href = baseUrl;
                }else {
                    showErrorBox("退出失败");
                }
            }
        })
    }
</script>
</html>
<!--<script src="js/my/logOut.js"></script>-->
<script src="js/my/headImgAndName.js"></script>
